package jiankao;


import java.io.File;
import java.lang.reflect.Array;
import java.util.*;

public class BianPai {

    public static void ysywl(List<Map<String,Object>> datas){

        List<Map<String,Object>> opDatas=new ArrayList<>();
        opDatas.addAll(datas);

        List<Map<String,Object>> lishiDatas=new ArrayList<>();
        List<Map<String,Object>> wuliDatas=new ArrayList<>();
        Iterator<Map<String,Object>> iterator=opDatas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.contains("历")){
                lishiDatas.add(data);
            }else{
                wuliDatas.add(data);
            }
        }

        SheetData sheetData=new SheetData(StaticNumber.baseFilepath+File.separator+StaticNumber.kaoshiType+"语数英历史物理.xlsx");

        StaticNumber.init();

        List<Map<String,Object>> result=new ArrayList<>();

        for(int i=1;i<=14;i++){
            result.addAll(sheetData.creatSheet(wuliDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  语数英历/物  座位表","ysylw"));
        }

        for(int i=15;i<=22;i++){
            result.addAll(sheetData.creatSheet(lishiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  语数英历/物  座位表","ysylw"));
        }

        sheetData.createResultSheet(datas,"总表",StaticNumber.kaoshiType+"语数英历史物理座位安排表","ysylw");

        Map<Integer,List<Map<String,Object>>> mapDatas=new HashMap<>();
        Iterator<Map<String,Object>> iterator1=datas.iterator();
        while (iterator1.hasNext()){
            Map<String,Object> mapData=iterator1.next();
            String classNumber= mapData.get("高二学号").toString();
            int classID=Integer.parseInt(classNumber.substring(0,classNumber.length()-2));
            if(mapDatas.get(classID)==null){
                mapDatas.put(classID,new ArrayList<Map<String, Object>>());
            }
            mapDatas.get(classID).add(mapData);
        }
    }

    public static void xiaokemu(List<Map<String,Object>> datas){//8*54+2*48+2*42

        List<Map<String,Object>> opDatas=new ArrayList<>();
        opDatas.addAll(datas);

        Map<String,List<Map<String,Object>>> map=new HashMap<>();
        Iterator<Map<String,Object>> iterator=opDatas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            String key=type.substring(1);
            if(!map.containsKey(key)){
                map.put(key,new ArrayList<Map<String, Object>>());
            }
            map.get(key).add(data);
        }

        SheetData sheetData=new SheetData("E:\\考试编排\\四校联考\\高二(上)四校联考四选二.xlsx");

        StaticNumber.init();

        List<Map<String,Object>> result=new ArrayList<>();

        List<String> fenbu=new ArrayList<String>(Arrays.asList("化政", "化政", "化政", "化生", "化生",
                "政地", "化生", "政地", "政地", "化生", "化生", "生政",
                "生地", "生政", "生政", "生地", "生政", "生政", "化地",
                "化地", "生地", "化地", "化地"
        ));

        for(int i=0;i<fenbu.size();i++){
            result.addAll(sheetData.creatSheet(map.get(fenbu.get(i)),((int)StaticNumber.getClassSize(i+1)/6),6,"第"+(i+1)+"考场",StaticNumber.kaoshiType+"  四选二  座位表","shengwu"));
        }



        sheetData.createResultSheet(datas,"总表",StaticNumber.kaoshiType+"四选二座位安排表","shengwu");
//        System.out.println(datas.get(0).get("考场"));

        Map<Integer,List<Map<String,Object>>> mapDatas=new HashMap<>();
        Iterator<Map<String,Object>> iterator1=datas.iterator();
        while (iterator1.hasNext()){
            Map<String,Object> mapData=iterator1.next();
            String classNumber= mapData.get("高二学号").toString();
            int classID=Integer.parseInt(classNumber.substring(0,classNumber.length()-2));
            if(mapDatas.get(classID)==null){
                mapDatas.put(classID,new ArrayList<Map<String, Object>>());
            }
            mapDatas.get(classID).add(mapData);
        }
    }

    public static void shengwu(List<Map<String,Object>> datas){//8*54+2*48+2*42

        List<Map<String,Object>> opDatas=new ArrayList<>();
        opDatas.addAll(datas);

        List<Map<String,Object>> shengwuDatas=new ArrayList<>();
        List<Map<String,Object>> zixiDatas=new ArrayList<>();
        Iterator<Map<String,Object>> iterator=opDatas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.contains("生")){
                shengwuDatas.add(data);
            }else{
                zixiDatas.add(data);
            }
        }
        opDatas.removeAll(zixiDatas);

        SheetData sheetData=new SheetData(StaticNumber.baseFilepath+File.separator+StaticNumber.kaoshiType+"生物.xlsx");

        StaticNumber.init();

        List<Map<String,Object>> result=new ArrayList<>();

        for(int i=1;i<=12;i++){
            result.addAll(sheetData.creatSheet(shengwuDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  生物  座位表","shengwu"));
        }

        for(int i=13;i<=22;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  生物自习  座位表","shengwu"));
        }

        sheetData.createResultSheet(datas,"总表",StaticNumber.kaoshiType+"生物座位安排表","shengwu");
//        System.out.println(datas.get(0).get("考场"));

        Map<Integer,List<Map<String,Object>>> mapDatas=new HashMap<>();
        Iterator<Map<String,Object>> iterator1=datas.iterator();
        while (iterator1.hasNext()){
            Map<String,Object> mapData=iterator1.next();
            String classNumber= mapData.get("高二学号").toString();
            int classID=Integer.parseInt(classNumber.substring(0,classNumber.length()-2));
            if(mapDatas.get(classID)==null){
                mapDatas.put(classID,new ArrayList<Map<String, Object>>());
            }
            mapDatas.get(classID).add(mapData);
        }
    }


    public static void dili(List<Map<String,Object>> datas){//10*48

        List<Map<String,Object>> opDatas=new ArrayList<>();
        opDatas.addAll(datas);

        List<Map<String,Object>> diliDatas=new ArrayList<>();
        List<Map<String,Object>> zixiDatas=new ArrayList<>();
        Iterator<Map<String,Object>> iterator=opDatas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.contains("地")){
                diliDatas.add(data);
            }else{
                zixiDatas.add(data);
            }
        }

//        System.out.println("地理人数:"+diliDatas.size());

        opDatas.removeAll(zixiDatas);

        SheetData sheetData=new SheetData(StaticNumber.baseFilepath+File.separator+StaticNumber.kaoshiType+"地理.xlsx");

        StaticNumber.init();

        List<Map<String,Object>> result=new ArrayList<>();

        for(int i=1;i<=10;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  地理自习  座位表","dili"));
        }

        for(int i=11;i<=20;i++){
            result.addAll(sheetData.creatSheet(diliDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  地理  座位表","dili"));
        }

        for(int i=21;i<=22;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  地理自习  座位表","dili"));
        }

        sheetData.createResultSheet(datas,"总表",StaticNumber.kaoshiType+"地理座位安排表","dili");
//        System.out.println(datas.get(0).get("考场"));

        Map<Integer,List<Map<String,Object>>> mapDatas=new HashMap<>();
        Iterator<Map<String,Object>> iterator1=datas.iterator();
        while (iterator1.hasNext()){
            Map<String,Object> mapData=iterator1.next();
            String classNumber= mapData.get("高二学号").toString();
            int classID=Integer.parseInt(classNumber.substring(0,classNumber.length()-2));
            if(mapDatas.get(classID)==null){
                mapDatas.put(classID,new ArrayList<Map<String, Object>>());
            }
            mapDatas.get(classID).add(mapData);
        }
    }

    public static void huaxue(List<Map<String,Object>> datas){//6*54+3*48+42*2

        List<Map<String,Object>> opDatas=new ArrayList<>();
        opDatas.addAll(datas);

        List<Map<String,Object>> huaxueDatas=new ArrayList<>();
        List<Map<String,Object>> zixiDatas=new ArrayList<>();
        Iterator<Map<String,Object>> iterator=opDatas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.contains("化")){
                huaxueDatas.add(data);
            }else{
                zixiDatas.add(data);
            }
        }
        opDatas.removeAll(zixiDatas);

        SheetData sheetData=new SheetData(StaticNumber.baseFilepath+File.separator+StaticNumber.kaoshiType+"化学.xlsx");

        StaticNumber.init();

        List<Map<String,Object>> result=new ArrayList<>();

        for(int i=1;i<=5;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  化学自习  座位表","huaxue"));
        }

        for(int i=6;i<=16;i++){
            result.addAll(sheetData.creatSheet(huaxueDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  化学  座位表","huaxue"));
        }

        for(int i=17;i<=22;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  化学自习  座位表","huaxue"));
        }

        sheetData.createResultSheet(datas,"总表",StaticNumber.kaoshiType+"化学座位安排表","huaxue");
//        System.out.println(datas.get(0).get("考场"));

        Map<Integer,List<Map<String,Object>>> mapDatas=new HashMap<>();
        Iterator<Map<String,Object>> iterator1=datas.iterator();
        while (iterator1.hasNext()){
            Map<String,Object> mapData=iterator1.next();
            String classNumber= mapData.get("高二学号").toString();
            int classID=Integer.parseInt(classNumber.substring(0,classNumber.length()-2));
            if(mapDatas.get(classID)==null){
                mapDatas.put(classID,new ArrayList<Map<String, Object>>());
            }
            mapDatas.get(classID).add(mapData);
        }
    }

    public static void zhengzhi(List<Map<String,Object>> datas){//8*54+2*48

        List<Map<String,Object>> opDatas=new ArrayList<>();
        opDatas.addAll(datas);

        List<Map<String,Object>> zhengzhiDatas=new ArrayList<>();
        List<Map<String,Object>> zixiDatas=new ArrayList<>();
        Iterator<Map<String,Object>> iterator=opDatas.iterator();
        while(iterator.hasNext()){
            Map<String,Object> data=iterator.next();
            String type= (String) data.get("类型");
            if(type.contains("政")){
                zhengzhiDatas.add(data);
            }else{
                zixiDatas.add(data);
            }
        }
        opDatas.removeAll(zixiDatas);

        SheetData sheetData=new SheetData(StaticNumber.baseFilepath+File.separator+StaticNumber.kaoshiType+"政治.xlsx");

        StaticNumber.init();

        List<Map<String,Object>> result=new ArrayList<>();

        for(int i=1;i<=8;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  政治自习  座位表","zhengzhi"));
        }

        for(int i=9;i<=19;i++){
            result.addAll(sheetData.creatSheet(zhengzhiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  政治  座位表","zhengzhi"));
        }

        for(int i=20;i<=22;i++){
            result.addAll(sheetData.creatSheet(zixiDatas,((int)StaticNumber.getClassSize(i)/6),6,"第"+i+"考场",StaticNumber.kaoshiType+"  政治自习  座位表","zhengzhi"));
        }

        sheetData.createResultSheet(datas,"总表",StaticNumber.kaoshiType+"政治座位安排表","zhengzhi");
//        System.out.println(datas.get(0).get("考场"));

        Map<Integer,List<Map<String,Object>>> mapDatas=new HashMap<>();
        Iterator<Map<String,Object>> iterator1=datas.iterator();
        while (iterator1.hasNext()){
            Map<String,Object> mapData=iterator1.next();
            String classNumber= mapData.get("高二学号").toString();
            int classID=Integer.parseInt(classNumber.substring(0,classNumber.length()-2));
            if(mapDatas.get(classID)==null){
                mapDatas.put(classID,new ArrayList<Map<String, Object>>());
            }
            mapDatas.get(classID).add(mapData);
        }
    }
}
